Skip to content

feat(dogstatsd): listen on UDP and the named pipe together - #181

Open
Lewis-E wants to merge 2 commits into
mainfrom
lewis/SVLS-9467/dogstatsd-dual-listen
Open

Lewis-E wants to merge 2 commits into
mainfrom
lewis/SVLS-9467/dogstatsd-dual-listen

Conversation

@Lewis-E

@Lewis-E Lewis-E commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

When DD_DOGSTATSD_WINDOWS_PIPE_NAME is set, dogstatsd now listens on UDP 8125 and the named pipe together, as #94 did for the trace agent. With a pipe set, the UDP bind is best-effort, as #129 did for TCP 8126. A failed bind logs a warning and dogstatsd keeps running on its pipe. Without a pipe, a failed bind still panics, so Linux, Lambda and Windows without a pipe behave as before.

datadog-serverless-compat no longer forces the dogstatsd port to 0 when a pipe is set. It logs the pipe listener, and the dogstatsd crate logs whether the UDP bind succeeded.

Motivation

SVLS-9467: Java multi-function named pipes on Azure Functions.

serverless-compat-java will give each function its own dogstatsd pipe. Customers on older configurations would lose custom metrics without any error if the binary stopped listening on UDP. We want an easy upgrade without breaking anything. This imitates the behavior of the trace named pipe.

Additional Notes

See also: TBD java-dogstatsd-client PR

Describe how to test/QA your changes

  • New Windows-only test_named_pipe_and_udp_dual_listen sends one metric over UDP and one over the pipe to one server, then checks that the flush contains both and that cancellation stops it. It follows Listen on both TCP and named pipes when a pipe name is configured #94's dual-transport test.
  • cargo clippy passes for x86_64-pc-windows-gnu with windows-pipes,windows-enhanced-metrics and on macOS. The Windows tests only run in Windows CI.
  • Planned: one pre-release end-to-end run with two Java functions on one shared plan.

When DD_DOGSTATSD_WINDOWS_PIPE_NAME is set, dogstatsd now keeps its UDP
listener alongside the pipe, as #94 did for the trace agent. Clients that
can't use a pipe, such as older java-dogstatsd-client versions, still
reach the binary over 8125.

With a pipe set, the UDP bind is best-effort, as #129 did for TCP 8126.
Several function apps share one VM on Elastic Premium and Dedicated plans,
so a second app's binary finds 8125 taken and must keep running on its
pipe. Without a pipe, a failed bind still panics.

datadog-serverless-compat no longer forces the dogstatsd port to 0 when a
pipe is set, and logs both listeners.

SVLS-9467
With a pipe set, main.rs logged "starting to listen on port 8125" even
when the best-effort UDP bind had failed. The dogstatsd crate now logs the
UDP listener at info when it binds, next to its existing warning when it
doesn't, and main.rs logs only the pipe in that case.

SVLS-9467
@Lewis-E
Lewis-E marked this pull request as ready for review October 15, 2026 20:23
Copilot AI balanced review requested due to automatic review settings October 15, 2026 20:23
@Lewis-E
Lewis-E requested review from a team as code owners October 15, 2026 20:23
@Lewis-E
Lewis-E requested review from duncanpharvey and lym953 and removed request for a team October 15, 2026 20:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Sustained UDP traffic can starve named-pipe consumption and cause unbounded queue growth.

1 open finding
What changed in this PR

Adds concurrent UDP and named-pipe DogStatsD listeners to preserve compatibility with older clients on Windows.

Changes:

  • Keeps UDP enabled when a pipe is configured, with best-effort binding.
  • Removes the compatibility binary’s port-zero override.
  • Adds a Windows dual-transport integration test.
File Description
crates/​dogstatsd/​tests/​integration_test.rs Tests receiving metrics through both transports and cancellation.
crates/​dogstatsd/​src/​dogstatsd.rs Combines transport reads and handles optional UDP binding.
crates/​datadog-serverless-compat/​src/​main.rs Preserves the configured UDP port alongside named pipes.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +171 to 177
// Drain only the UDP side; the named pipe channel is read by `read_into`.
#[cfg(all(windows, feature = "windows-pipes"))]
BufferReader::NamedPipe {
udp_socket: Some(socket),
..
} => try_recv_udp(socket, buf),
// Non-UDP transports don't support non-blocking reads

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants